package com.itheima.Controller;

import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpQueryParam;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("emps")
public class EmpController {
    @Autowired
    private EmpService empService;
    //分页条件查询
    @GetMapping
    public Result page(EmpQueryParam empQueryParam){
        PageResult pageResult = empService.page(empQueryParam);
        return Result.success(pageResult);
    }

    //增加员工数据
    @PostMapping
    public Result save(@RequestBody Emp emp){
        empService.save(emp);
        return Result.success();
    }

    //作业一：查询全部员工
    @GetMapping("/list")
    public Result selectAll(){
        List<Emp> empList = empService.selectAll();
        return Result.success(empList);
    }

    //    批量删除员工
    @DeleteMapping
    public  Result delete(@RequestParam List<Integer> ids){
        empService.delete(ids);
        return  Result.success();

    }
    //    回显(修改)
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id){
        Emp emp= empService.getInfo(id);
        return Result.success(emp);


    }
    //    修改
    @PutMapping
    public  Result update(@RequestBody Emp emp){
        empService.update(emp);
        return Result.success();

    }
}
